<template>
	<view class="details">
		<view class="title">
			任务内容
		</view>
		<view class="content">
			{{content}}
		</view>
		<button type="default" style="background: #2B85E4;margin-top: 50rpx; color: #FFFFFF;font-size: 35rpx;"
			@click="copy(Url)">复制链接</button>
		<view class="" style="padding: 0 30rpx; width: 100%; position:fixed;bottom: 50rpx;width: 100%;left: 0;">
			<button type="default" style="width: 100%;background: #2B85E4;color: #FFFFFF;font-size: 35rpx;"
				@click="receive">{{text}}</button>
		</view>
	</view>
</template>

<script>
	import {
		getTask
	} from '@/api/user.js';
	export default {
		data() {
			return {
				type: true,
				text: "领取任务",
				Url: "",
				content: "",
				id: '',
				price: '',
				title: ''
			}
		},
		onLoad(e) {
			console.log(e)
			this.price = e.price
			this.id = e.id
			this.title = JSON.parse(e.title)
			this.content = JSON.parse(e.content)
			this.Url = e.url
			this.cid=e.cid
			let _this = this
			uni.getStorage({
				key: 'type',
				success: function(res) {
					console.log(res.data);
					this.type = res.data
					if (this.type === false) {
						uni.showToast({
							title: '已经领取',
							duration: 2000,
							icon: "none"
						});
						_this.text = "已经领取",
							_this.type = false
					}
				}
			});
		},
		methods: {
			//复制链接
			copy(value) {
				let _this = this;
				uni.setClipboardData({
					data: value, //要被复制的内容
					success: function() {
						//重点~做笔记
						//在success中加入uni.hideToast()可以解决
						uni.showToast({
							title: '复制成功',
							duration: 1000,
							icon: 'success'
						});
						

						
						// 判断平台  
						if (plus.os.name == 'Android') {
							if(_this.cid==1){
								console.log("抖音")
								plus.runtime.launchApplication({
										pname: 'com.ss.android.ugc.aweme'
									},
									function(e) {
										console.log('Open system default browser failed: ' + e.message);
									}
								);
							}else if(_this.cid==2){
								console.log("西瓜")
								plus.runtime.launchApplication({
										pname: 'com.ss.android.article.video',
									
									},
									function(e) {
										console.log('Open system default browser failed: ' + e.message);
									}
								);
							}else if(_this.cid==3){
								console.log("今日")
								plus.runtime.launchApplication({
										pname: 'com.ss.android.article.news'
									},
									function(e) {
										console.log('Open system default browser failed: ' + e.message);
									}
								);
							}
						} 
						// else if (plus.os.name == 'iOS') {
						// 	plus.runtime.launchApplication({
						// 		action: 'snssdk1128://'
						// 	}, function(e) {
						// 		console.log('Open system default browser failed: ' + e.message);
						// 	});
						// }
						// uni.navigateTo({
						// 	url:"./url?url="+value,
						// 	animationDuration:2000
						// })
						// if (plus.os.name == 'Android') {
						//安卓
						// plus.runtime.openURL(
						// 	'snssdk1128://',
						// 	function(res) {
						// 		console.log(res);
						// 	}
						// );
						// plus.runtime.openURL("snssdk1128://search/trending?type=1",function(res){
						// console.log(res)
						// })
						// if (
						// 	plus.runtime.isApplicationExist({
						// 		//查看安卓系统手机有没有下载这款app
						// 		pname: 'com.ss.android.ugc.aweme' //微信app云打包的包名
						// 	})
						// ) {
						// 	//安装了app
						// 	plus.runtime.openURL(
						// 		'snssdk1128://',
						// 		function(res) {
						// 			console.log(res);
						// 		}
						// 	);
						// } 
						// else {
						// 	//未安装app
						// 	uni.showModal({
						// 		title: '提示',
						// 		content: '您还没有此APP,去下载',
						// 		success: function(res) {
						// 			if (res.confirm) {
						// 				plus.runtime.openURL('https://www.douyin.com/home', function(res) {
						// 					console.log(res);
						// 				});
						// 			} else if (res.cancel) {
						// 				console.log('用户点击取消');
						// 			}
						// 		}
						// 	});
						// }
						// } 
					},
					fail: function(err) {
						uni.showToast({
							title: '复制失败',
							duration: 2000,
							icon: 'none'
						});
					}
				});
			},
			//领取任务
			receive() {
				let data = {
					task_id: this.id,
					title: this.title,
					content: this.content,
					price: this.price
				}
				getTask(data).then(res => {
					console.log(res)
					uni.showToast({
						title: res.msg,
						duration: 2000,
						icon: "none"
					});
				}, err => {})
				// if(this.type){
				// 	uni.showToast({
				// 		title: '领取成功',
				// 		duration: 2000,
				// 		icon: 'success'
				// 	});
				// 	this.text="已经领取",
				// 	this.type=false
				// 	uni.setStorage({
				// 	    key: 'type',
				// 	    data: this.type,
				// 	    success: function () {
				// 	        // console.log('success');
				// 	    }
				// 	});
				// }else{
				// 	uni.showToast({
				// 		title: '已经领取',
				// 		duration: 2000,
				// 		icon:"none"
				// 	});
				// }
			},
			//获取任务
		}
	}
</script>

<style lang="less">
	.details {
		position: relative;
		padding: 0 30rpx;

		.title {
			margin-top: 50rpx;
			font-size: 40rpx;
			font-weight: bold;
			color: #000000;
		}

		.content {
			margin-top: 20rpx;
		}
	}
</style>
